<?php
include_once '../model/Sales.php';
include_once '../model/SalesItem.php';
include_once '../model/Customer.php';
include_once '../model/Product.php';
include_once '../util/database_conn.php';

session_start();

function millitime() {
  $microtime = microtime();
  $comps = explode(' ', $microtime);  
  return sprintf('%d%03d', $comps[1], $comps[0] * 1000);
}

$sale = new Sales();
$sale->setId(millitime());
$sale->setSalesDate($_POST['sales_date']);
$sale->setSalesNumber($_POST['sales_number']);
$sale->setCustomer(Customer::load($_POST['id']));
$sale->setItems($_SESSION['items']);

$sale->save();

session_destroy();

mysql_close($conn);
?>
